package com.zhuiYun.project.api.userinfo.controller;

import com.zhuiYun.project.api.login.entity.User;
import com.zhuiYun.project.api.userinfo.service.UserInfoService;
import com.zhuiYun.project.common.controller.BaseController;
import com.zhuiYun.project.common.errorCode.CommonException;
import com.zhuiYun.project.common.response.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName UserInfoController
 * @Description TODO 用户信息控制层
 * @Author 赵笛
 * @Date 2023/4/10 13:53
 **/
@RestController
@RequestMapping("/user/info/")
@Api(tags = "用户信息管理")
@Slf4j
@CrossOrigin
public class UserInfoController extends BaseController{
    @Autowired
    UserInfoService userInfoService;
    /**
    * @Author 赵笛
    * @Description TODO 发送邮件验证码
    * @Date 2023/4/10 14:06
    * @Return com.zhuiYun.project.common.response.CommonResult
    * @param mail 邮箱
    * @param operationStatus 操作状态（0为解绑，1为绑定）
    */
    @GetMapping("/sendMailVerificationCode")
    @ApiOperation(value = "发送邮件验证码的方法")
    public CommonResult sendMailVerificationCode(String mail,Integer operationStatus)throws CommonException{
        log.info("发送邮件验证码");
        return userInfoService.sendMailVerificationCode(mail,operationStatus);
    }

    /**
    * @Author 赵笛
    * @Description TODO 校验验证码
    * @Date 2023/4/10 15:43
    * @Return com.zhuiYun.project.common.response.CommonResult
    * @param mail
    * @param vcode
    */
    @GetMapping("/checkMailVerificationCode")
    @ApiOperation(value = "校验验证码的方法")
    public CommonResult checkMailVerificationCode(String mail,String vcode)throws CommonException{
        log.info("校验验证码");
        return userInfoService.checkMailVerificationCode(mail,vcode);
    }

    /**
    * @Author 赵笛
    * @Description TODO 修改当前用户信息
    * @Date 2023/4/10 18:42
    * @Return com.zhuiYun.project.common.response.CommonResult
    * @param user
    */
    @PostMapping("/updateUserInfo")
    @ApiOperation(value = "修改当前用户信息")
    public CommonResult updateUserInfo(@RequestBody User user)throws CommonException{
        log.info("修改当前用户信息");
        return userInfoService.updateUserInfo(user);
    }

    /**
     * @Author 赵笛
     * @Description TODO 根据当前用户id查询收藏商品个数
     * @Date 2023/4/10 20:07
     * @Return com.zhuiYun.project.common.response.CommonResult
     * @param userId
     */
    @GetMapping("/getCommodityCollectionCountByUserId")
    @ApiOperation(value = "根据当前用户id查询收藏商品个数")
    public CommonResult getCommodityCollectionCountByUserId(Integer userId)throws CommonException {
        log.info("根据当前用户id查询收藏商品个数");
        return userInfoService.getCommodityCollectionCountByUserId(userId);
    }
    /**
    * @Author 赵笛
    * @Description TODO 根据当前用户id查询收藏diy个数
    * @Date 2023/4/11 8:53
    * @Return com.zhuiYun.project.common.response.CommonResult
    * @param userId
    */
    @GetMapping("/getDiyCollectionCountByUserId")
    @ApiOperation(value = "根据当前用户id查询收藏diy个数")
    public CommonResult getDiyCollectionCountByUserId(Integer userId)throws CommonException{
        log.info("根据当前用户id查询收藏商品个数");
        return userInfoService.getDiyCollectionCountByUserId(userId);
    }
    /**
     * @Author 赵笛
     * @Description TODO 根据当前用户查找浏览记录数量
     * @Date 2023/4/12 9:21
     * @Return com.zhuiYun.project.common.response.CommonResult
     * @param userId
     */
    @GetMapping("/getUserHistoryCountByUserId")
    @ApiOperation(value = "根据当前用户查找浏览记录数量")
    public CommonResult getUserHistoryCountByUserId(Integer userId) throws CommonException {
        log.info("根据当前用户查找浏览记录");
        return userInfoService.getUserHistoryCountByUserId(userId);
    }
}
